package com.edu.zju.scs.panacea.mapper.plan;

import com.edu.zju.scs.panacea.entity.plan.Industry;
import com.edu.zju.scs.panacea.entity.plan.Qualification;
import com.edu.zju.scs.panacea.entity.query.QualificationQuery;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: Yue Liang
 * @Date: 2018-12-30 16:02
 */
@Repository
public interface QualificationMapper {
    @Select("SELECT * FROM plan_qualification WHERE id = #{id}")
    @Results(id="qualificationMap", value={
            @Result(id=true,property="id",column="id"),
            @Result(property="sellerId",column="seller_id"),
            @Result(property="industryId",column="industry_id"),
            @Result(property="name",column="name"),
            @Result(property="url",column="url"),
            @Result(property="state",column="state")})
    Qualification selectQualification(Long id);


    @Select("SELECT * FROM plan_qualification")
    @ResultMap(value = "qualificationMap")
    List<Qualification> selectAllQualification();

    @Select("<script>" +
            "SELECT * FROM plan_qualification where 1=1 " +
            " <if test='sellerId != null'> and seller_id = #{sellerId} </if> "+
            " <if test='industryId != null'> and industry_id = #{industryId} </if> "+
            "</script>")
    @ResultMap(value = "qualificationMap")
    List<Qualification> selectSpecificQualification(QualificationQuery qualificationQuery);

    @Delete("DELETE FROM plan_qualification where id = #{id}")
    long deleteQualification(Long id);

    @Insert("INSERT INTO plan_qualification(seller_id, industry_id, name, url, state) VALUES (#{sellerId}, #{industryId}, #{name}, #{url}, #{state})")
    @Options(useGeneratedKeys=true)
    long insertQualification(Qualification qualification);

    @Update({ "update plan_qualification set seller_id = #{sellerId}, industry_id = #{industryId}, name = #{name}, url = #{url}, state = #{state} where id = #{id}" })
    long updateQualification(Qualification qualification);
}
